package com.kyzh.core.utils

import android.app.Activity
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.kyzh.core.MyApplication

fun ImageView.loadImage(context: Activity,url:String){
    if(!context.isDestroyed){
        Glide.with(context).load(url).into(this)
    }
}
fun ImageView.loadImage(url:String?){
    Glide.with(MyApplication.instance).load(url).into(this)
}
fun ImageView.loadGif(url:String?){
    Glide.with(context).asGif().load(url).into(this)
}
fun ImageView.loadImage(url:String?,radius:Int){
    val corners = RoundedCorners(radius)
    val options = RequestOptions.bitmapTransform(corners)
    Glide.with(MyApplication.instance).load(url).apply(options).into(this)
}

fun ImageView.loadImage1(url:String?){
    Glide.with(MyApplication.instance).load(url) .apply( RequestOptions()
        .transforms( CenterCrop(),  RoundedCorners(1)
        )).into(this)
}